/* The code examples copyrighted by Nokia Corporation that are included to
 * this material are licensed to you under following MIT-style License:
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
import Qt 4.7
import com.meego 1.0
import com.meego.extras 1.0

Page {
    id: sendMailPage
    Flickable {
        id: container
        anchors.fill: parent
	anchors.margins: 10
        flickableDirection: Flickable.VerticalFlick

        QueryDialog {
            id: errorDialog
            titleText: "Error"
            message: "Failed to send message"
            acceptButtonText: "Ok"
        }
        Column {
            width: parent.width                    
            Grid {
                columns: 2
                Label {
                    id: receiverLabel
                    text: "Receiver:"
                }

                TextField {
                    id: receiverText
                }

                Label {
                    id: subjectLabel
                    text: "Subject:"
                }

                TextField {
                    id: subjectText
                }

                Label {
                    text: "Sender:"
                    verticalAlignment: Text.AlignVCenter
                }

                ListView {
                    id: senderList
                    clip: true
                    model: SenderAccountModel
                    width: sendMailPage.width - x
                    height: sendMailPage.height / 4
                    delegate:
                        Text {
                            text: nametext + "(" + messagetype + ")" 
                            width: parent.width
                            font.pointSize: 17
                            MouseArea { anchors.fill: parent; onClicked:senderList.currentIndex = index }
                    }
                    highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
                    highlightFollowsCurrentItem: true
                }
            }

            Button {
                id: sendButton
                text: "Send message"
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    if (SendMailExample.sendMail(receiverText.text, subjectText.text, mailText.text, senderList.currentIndex)) {
                    }
                    else {
                        errorDialog.open();
                    }
                }
            }

            TextArea {
                id: mailText
                anchors {left: parent.left; right: parent.right;}
                placeholderText: "Enter message here"
            }
        }
    }
}
